package com.yaoyong.yy_demo.module.mail;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/mail")
@Tag(name = "发送邮件演示controller", description = "模拟发送各种邮件")
public class MailController {

    @Autowired
    MailService mailService;


    @Operation(summary = "发送简单邮件接口", description = "发送简单邮件")
    @PostMapping(value = "/sendSimpleMail")
    public ResponseEntity<Void> sendSimpleMail(@RequestBody Email email) {
        try {
            mailService.sendSimpleMail(email);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @Operation(summary = "发送带附件的邮件接口", description = "带附件的邮件")
    @PostMapping(value = "/sendAttachFileMail")
    public ResponseEntity<Void> sendAttachFileMail(@RequestBody Email email) {
        try {
            mailService.sendAttachFileMail(email);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }


    @Operation(summary = "发送带图片的邮件接口", description = "带图片的邮件")
    @PostMapping(value = "/sendMailWithImg")
    public ResponseEntity<Void> sendMailWithImg(@RequestBody Email email) {
        try {
            mailService.sendMailWithImg(email);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

    @Operation(summary = "使用thymeleaf模板的邮件接口", description = "使用thymeleaf模板")
    @PostMapping(value = "/sendHtmlMail")
    public ResponseEntity<Void> sendHtmlMail(@RequestBody Email email) {
        try {
            mailService.sendHtmlMail(email);
            return ResponseEntity.ok(null);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(null);
    }

}
